//
//  ModelGetCRSource.m
//  MexicoLoan
//
//  Created by wxp on 2025/3/20.
//

#import "ModelGetCRSource.h"

NSString *const kModelGetCRSourceCloudunExpire = KEY_cloudunExpire;
NSString *const kModelGetCRSourceFicoInfoError = KEY_ficoInfoError;
NSString *const kModelGetCRSourceFicoExpireTime = KEY_ficoExpireTime;
NSString *const kModelGetCRSourceFicoExpire = KEY_ficoExpire;
NSString *const kModelGetCRSourceFicoScore = KEY_ficoScore;
NSString *const kModelGetCRSourceCloudunScore = KEY_cloudunScore;
NSString *const kModelGetCRSourceFicoshow = KEY_ficoshow;
NSString *const kModelGetCRSourceCloudunExpireTime = KEY_cloudunExpireTime;

NSString *const kModelGetCRSourceIsHaveFicoScore = @"isHaveFicoScore";
NSString *const kModelGetCRSourceIsHaveCloudunScore = @"isHaveCloudunScore";

@interface ModelGetCRSource ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation ModelGetCRSource

@synthesize cloudunExpire = _cloudunExpire;
@synthesize ficoInfoError = _ficoInfoError;
@synthesize ficoExpireTime = _ficoExpireTime;
@synthesize ficoExpire = _ficoExpire;
@synthesize ficoScore = _ficoScore;
@synthesize cloudunScore = _cloudunScore;
@synthesize ficoshow = _ficoshow;
@synthesize cloudunExpireTime = _cloudunExpireTime;

@synthesize isHaveFicoScore = _isHaveFicoScore;
@synthesize isHaveCloudunScore = _isHaveCloudunScore;

+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict {
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict {
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if (self && [dict isKindOfClass:[NSDictionary class]]) {
        self.cloudunExpire = [[self objectOrNilForKey:kModelGetCRSourceCloudunExpire fromDictionary:dict] boolValue];
        self.ficoInfoError = [[self objectOrNilForKey:kModelGetCRSourceFicoInfoError fromDictionary:dict] boolValue];
        self.ficoExpireTime = [[self objectOrNilForKey:kModelGetCRSourceFicoExpireTime fromDictionary:dict] doubleValue];
        self.ficoExpire = [[self objectOrNilForKey:kModelGetCRSourceFicoExpire fromDictionary:dict] boolValue];
        self.ficoScore = [[self objectOrNilForKey:kModelGetCRSourceFicoScore fromDictionary:dict] doubleValue];
        self.cloudunScore = [[self objectOrNilForKey:kModelGetCRSourceCloudunScore fromDictionary:dict] doubleValue];
        self.ficoshow = [[self objectOrNilForKey:kModelGetCRSourceFicoshow fromDictionary:dict] boolValue];
        self.cloudunExpireTime = [[self objectOrNilForKey:kModelGetCRSourceCloudunExpireTime fromDictionary:dict] doubleValue];
        
        self.isHaveFicoScore = [dict.allKeys containsObject:KEY_ficoScore]?true:false;
        self.isHaveCloudunScore = [dict.allKeys containsObject:KEY_cloudunScore]?true:false;
    }
    return self;
}

- (NSDictionary *)dictionaryRepresentation {
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:[NSNumber numberWithBool:self.cloudunExpire] forKey:kModelGetCRSourceCloudunExpire];
    [mutableDict setValue:[NSNumber numberWithBool:self.ficoInfoError] forKey:kModelGetCRSourceFicoInfoError];
    [mutableDict setValue:[NSNumber numberWithDouble:self.ficoExpireTime] forKey:kModelGetCRSourceFicoExpireTime];
    [mutableDict setValue:[NSNumber numberWithBool:self.ficoExpire] forKey:kModelGetCRSourceFicoExpire];
    [mutableDict setValue:[NSNumber numberWithDouble:self.ficoScore] forKey:kModelGetCRSourceFicoScore];
    [mutableDict setValue:[NSNumber numberWithDouble:self.cloudunScore] forKey:kModelGetCRSourceCloudunScore];
    [mutableDict setValue:[NSNumber numberWithBool:self.ficoshow] forKey:kModelGetCRSourceFicoshow];
    [mutableDict setValue:[NSNumber numberWithDouble:self.cloudunExpireTime] forKey:kModelGetCRSourceCloudunExpireTime];
    
    [mutableDict setValue:[NSNumber numberWithBool:self.isHaveFicoScore] forKey:kModelGetCRSourceIsHaveFicoScore];
    [mutableDict setValue:[NSNumber numberWithBool:self.isHaveCloudunScore] forKey:kModelGetCRSourceIsHaveCloudunScore];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description  {
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict {
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}

@end
